from kazoo.client import KazooState
from kazoo.client import KazooClient
import logging

logging.basicConfig()

def my_listener(state):
    if state == KazooState.LOST:
        print "KazooState.LOST"
    elif state == KazooState.SUSPENDED:
        print "KazooState.SUSPENDED"
    else:
        print "KazooState.CONN"

def addephemeralnode(zk, path):
    '''创建一个临时节点'''
    if zk.exists(path):
        print "ephemeral  exists"
    else:
        print "ephemeral not exists"
    zk.create(path, b"ephemeral" , ephemeral= False)

def addephemeralnode(zk, path):
    '''创建一个临时节点'''
    if zk.exists(path):
        print "ephemeral  exists"
    else:
        print "ephemeral not exists"
    zk.create(path, b"ephemeral" , ephemeral= False)
    
zk = KazooClient(hosts='192.168.99.110:2181', read_only=True)
zk.start()
zk.add_listener(my_listener)
if zk.exists("/Root"):
    b = zk.delete("/Root")
zk.create("/Root" , b"root1")
data = zk.get("/Root")

addephemeralnode(zk, "/ephemeral")

b = zk.delete("/Root")
zk.stop()